package com.ruoyi.business.mapper;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.business.domain.OrderInfo;
import com.ruoyi.business.domain.bo.admin.AdminCompanySettleAccountsQueryBo;
import com.ruoyi.business.domain.bo.admin.AdminOrderQueryBo;
import com.ruoyi.business.domain.vo.OrderInfoVo;
import com.ruoyi.business.domain.vo.admin.AdminCompanySettleAccountsVo;
import com.ruoyi.business.domain.vo.admin.AdminOrderDriverVo;
import com.ruoyi.business.domain.vo.admin.AdminOrderExportVo;
import com.ruoyi.common.core.mapper.BaseMapperPlus;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.List;

/**
 * 订单信息Mapper接口
 *
 * @author ruoyi
 * @date 2024-04-20
 */
public interface OrderInfoMapper extends BaseMapperPlus<OrderInfoMapper, OrderInfo, OrderInfoVo> {


    /**
     * 更新订单紧急状态
     *
     * @param orderId 订单id
     * @param name    运单名称
     * @param remark  运单备注
     * @return
     */
    default int updateUrgent(Long orderId, String name, String remark) {
        return update(null, new LambdaUpdateWrapper<OrderInfo>()
            .eq(OrderInfo::getOrderId, orderId)
            .set(OrderInfo::getIsUrgency, name)
            .set(OrderInfo::getRemark, remark));
    }

    /**
     * 根据状态统计订单数量
     *
     * @param status
     * @return
     */
    long countByStatus(@Param("status") List<String> status);

    /**
     * 修改订单状态
     *
     * @param id     订单ID
     * @param status 订单状态
     * @return
     */
    default int updateStatus(Long id, String status) {
        return update(null, new LambdaUpdateWrapper<OrderInfo>()
            .eq(OrderInfo::getOrderId, id)
            .set(OrderInfo::getOrderStatus, status));
    }

    /**
     * 修改订单可开票金额
     *
     * @param id     订单id
     * @param amount 可开票金额id
     * @return
     */
    default int updateInvoiceAmount(Long id, BigDecimal amount) {
        return update(null, new LambdaUpdateWrapper<OrderInfo>()
            .eq(OrderInfo::getOrderId, id)
            .set(OrderInfo::getRemainingInvoiceAmount, amount));
    }

    /**
     * 根据订单id获取订单司机信息
     *
     * @param orderId 订单id
     * @return
     */
    List<AdminOrderDriverVo> selectDriverVoList(Long orderId);

    /**
     * 查询公司结算账单列表
     *
     * @param page    分页对象
     * @param queryBo 查询条件
     */
    IPage<AdminCompanySettleAccountsVo> selectCompanySettleAccountsList(@Param("page") Page<AdminCompanySettleAccountsVo> page, @Param("queryBo") AdminCompanySettleAccountsQueryBo queryBo);

    /**
     * 查询订单导出信息
     *
     * @param queryBo
     * @return
     */
    List<AdminOrderExportVo> selectExportVoList(AdminOrderQueryBo queryBo);
}
